BUG#1849 - Count images as used if they are put into a category (site pref)
[lhc/web/wiklou.git] / includes / SpecialUnusedimages.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /** */
9 require_once("QueryPage.php");
10
11 /**
12 * @package MediaWiki
13 * @subpackage SpecialPage
14 */
15 class UnusedimagesPage extends QueryPage {
16
17 function getName() {
18 return 'Unusedimages';
19 }
20
21 function sortDescending() {
22 return false;
23 }
24 function isSyndicated() { return false; }
25
26 function getSQL() {
27 global $wgCountCategorizedImagesAsUsed;
28 $dbr =& wfGetDB( DB_SLAVE );
29
30 if ( $wgCountCategorizedImagesAsUsed ) {
31 extract( $dbr->tableNames( 'cur', 'image', 'imagelinks', 'categorylinks' ) );
32
33 return 'SELECT img_name as title, img_user, img_user_text, img_timestamp as value, img_description
34 FROM ((('.$cur.' AS I LEFT JOIN '.$categorylinks.' AS L ON I.cur_id = L.cl_from)
35 LEFT JOIN '.$imagelinks.' AS P ON I.cur_title = P.il_to)
36 INNER JOIN '.$image.' AS G ON I.cur_title = G.img_name)
37 WHERE I.cur_namespace = '.NS_IMAGE.' AND L.cl_from IS NULL AND P.il_to IS NULL';
38 }
39 else {
40 extract( $dbr->tableNames( 'image','imagelinks' ) );
41
42 return 'SELECT img_name as title, img_user, img_user_text, img_timestamp as value, img_description' .
43 ' FROM '.$image.' LEFT JOIN '.$imagelinks.' ON img_name=il_to WHERE il_to IS NULL ';
44 }
45 }
46
47 function formatResult( $skin, $result ) {
48 global $wgLang, $wgContLang;
49 $title = Title::makeTitle( NS_IMAGE, $result->title );
50
51 $imageUrl = htmlspecialchars( Image::imageUrl( $result->title ) );
52 $return =
53 # The 'desc' linking to the image page
54 '('.$skin->makeKnownLinkObj( $title, wfMsg('imgdesc') ).') '
55 # Link to the image itself
56 . '<a href="' . $imageUrl . '">' . htmlspecialchars( $title->getText() ) . '</a>'
57 # Last modified date
58 . ' . . '.$wgLang->timeanddate($result->value)
59 # Link to username
60 . ' . . '.$skin->makeLinkObj( Title::makeTitle( NS_USER, $result->img_user_text ), $result->img_user_text)
61 # If there is a description, show it
62 . $skin->commentBlock( $result->img_description );
63
64 return $return;
65 }
66
67 function getPageHeader() {
68 return wfMsg( "unusedimagestext" );
69 }
70
71 }
72
73 /**
74 * Entry point
75 */
76 function wfSpecialUnusedimages() {
77 list( $limit, $offset ) = wfCheckLimits();
78 $uip = new UnusedimagesPage();
79
80 return $uip->doQuery( $offset, $limit );
81 }
82 ?>